'use strict';

import * as actions from '../../actions/ring_zhekou_list';

// 对页面prop 数据进行管理
const initialState = {
  loading: false,
  error:false,
  loginError:false,
  message:"",
};
const defaultAction = {
  type: 'doNothing'
};

export default function index(state = initialState, action = defaultAction ) {

  switch (action.type) {
    case actions.LOAD_START:
      return Object.assign({}, state, {
        loading:true,
        error:false,
        loginError:false
      });
	  break;
    case actions.LOAD_ERR:
      return Object.assign({}, state, {
        loading:false,
		error:true,
		loginError:action.loginFalse,
		message:action.message
      });
	  break;
    case actions.GET_LIST_DONE:
      return Object.assign({}, state, {
        loading:false,
        error:false,
        loginError:false,
		data:action.data,
        activityId:action.activityId
      });
	  break;
    case actions.CLOSE_DIALOG:
      return Object.assign({}, state, {
		error:action.visible,
        loginError:false
      });
	  break;
    case actions.EDIT_ACTIVE:
	  state.data.activity_list.common_item_activity.map((act,key)=>{
		if(act.activity_id==action.data.activity_id){
			state.data.activity_list.common_item_activity[key]=action.data;
		}
	  });
      return Object.assign({}, state, {
        loading:false,
        error:false,
        loginError:false
	  });
	  break;
    case actions.REMOVE_ACTIVE:
	  state.data.activity_list.common_item_activity.map((act,key)=>{
		  if(act.activity_id==action.activity_id){
				state.data.activity_list.common_item_activity.splice(key,1);
			}
	  });
      return Object.assign({}, state, {
        loading:false,
        error:false,
        loginError:false
	  });
	  break;
    default:
      return state;
  }
}

